Ask a Question
Send an email to me.
 
Java Question and Answer Forums
JavaRanch Big Moose Saloon
Marcus Green's Discussion Forum
java.sun.com Forums, Chat and User Groups
Artima Java Answers Forum
 
Other Resources
Java Language Specification
Java Virtual Machine Specification
Java 2 Platform, Standard Edition, v 1.4.0 API Specification
 
Tutorials
Learning the Java Language
Operator Precedence Chart, Expressions, Statements, Blocks
Programming with Assertions
 
Answers: Certified Java Programmer Mock Exam
No.AnswerRemark
1g  None of the Above  Section 12.1.4 of the Java Language Specification states the following, "The method main must be declared public, static, and void. It must accept a single argument that is an array of Strings." In each of the three class declarations, the single argument is indeed an array of Strings.  
2f  Compiler Error  Variables declared inside of a block or method are called local variables and they are not automatically initialized. (Locally declared arrays are an exception to the rule, but none are used in this question.) The compiler will generate an error as a result of the attempt to access the local variables before a value has been assigned.  
3b  d  f  i  j  k  catch  instanceof  const  goto  import  transient  Both "const" and "goto" are java keywords, but neither is used.  
4b  Prints: null  Null is converted to a string and is printed as the word null.  
5c  e  g  i  const  continue  extends  break  Both "const" and "goto" are java keywords, but neither is used. All of the letters of all java keywords are lower case. In this question, the letter O of the word "instanceof" was upper case.  
6d  e  f  Run time error at line 2.  Run time error at line 5.  Run time error at line 8.  Section 12.1.4 of the Java Language Specification states the following, "The method main must be declared public, static, and void. It must accept a single argument that is an array of Strings." The rule is not enforced by the compiler, but should instead be enforced by the Java Virtual Machine. However, not every JVM enforces the rule. Even so, for the purposed of the SCJP exam, the main method should be declared as stated in the Java Language Specification. In this example, each of the three main methods generates a run-time exception because they are not declared static.  
7b  d  e  f  g  h  goto  package  synchronized  default  interface  volatile  Both "const" and "goto" are java keywords, but neither is used.  
8e  None of the Above  Unicode literals are declared using single quotes but none of the declarations here use single quotes. The declaration of char, b, is also problematic because it contains more than one char.  
9b  g  i  goto  implements  const  Both "const" and "goto" are java keywords, but neither is used.  
10b  Prints: BCD  The index for the first element of an array is zero.  
11d  Prints: -128,127  A byte is an 8 bit signed value.  
12c  Prints: 7f,ffff,7fff  A byte is an 8 bit signed value. A char is a 16 bit unsigned value. A short is a 16 bit signed value. The left most bit of a signed value is the sign bit. The sign bit is zero for positive numbers and one for negative numbers. The hexadecimal value 7f is equal to the decimal value 127. The hexadecimal value ff is equal to the decimal value negative 128.  
13a  boolean b1 = true;  There are two primitive boolean values: true and false. Both must be written with lower case letters. Although the C programming language accepts zero as a boolean value, the Java programming language does not.  
14b  Prints: -32768,32767  A short is a 16 bit signed value.  
15b  Prints: 8000000000000000,7fffffffffffffff  A long is a 64 bit signed value. The left most bit is the sign bit. The sign bit is zero for positive numbers and one for negative numbers.  
16e  f  Run time error at line 5.  Run time error at line 8.  Section 12.1.4 of the Java Language Specification states the following, "The method main must be declared public, static, and void. It must accept a single argument that is an array of Strings." The rule is not enforced by the compiler, but should instead be enforced by the Java Virtual Machine. However, not every JVM enforces the rule. Even so, for the purposed of the SCJP exam, the main method should be declared as stated in the Java Language Specification. Note: the Java Language Specification provides the option to disallow the declaration of more than one class in a single source code file if more than one of the classes in the file is referred to by code that exists outside of the file. The restriction is stated as an option and not a requirement. This option is not enforced by any compiler that I have tested.  
17e  Compiler Error.  Teal.b1 is always initialized because it is a class member. Arrays are always initialized even if declared locally. Local variable b2 is not initialized because it is local. Consequentially, a compiler error is generated when the attempt is made to print the value of b2.  
18c  Prints 0,0.0,0.0,false,null  Generally speaking, numberic type variables are initialized to zero. Booleans are initialized to false. Reference type variables are initialized to null.  
19a  Prints: 0,0,0,0,0,null   

Copyright © 2002, Dan Chisholm
All rights reserved.
1